<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class Item extends Model
{
    use SoftDeletes;
    protected $guarded = ['id'];

    public function fee()
    {
    	return $this->hasMany(ItemFee::class);
    }

    public function getReceiveAmount($contacter='')
    {
        $where['item_id'] = $this->id;
        if($contacter){
            $where['receive_contacter'] = $contacter;
        }
    	return ItemFee::where($where)->sum('receive_money');
    }

    public function getPayAmount($contacter='')
    {
    	$where['item_id'] = $this->id;
       
        if($contacter){
            $where['pay_contacter'] = $contacter;
        }
        return ItemFee::where($where)->sum('pay_money');
    }

    public function getReceiveFee($fee_name,$contacter='')
    {
    	$where['item_id'] = $this->id;
    	$where['fee_name'] = $fee_name;
        if($contacter){
            $where['receive_contacter'] = $contacter;
        }

    	return ItemFee::where($where)->value('receive_money');
    }

    public function getPayFee($fee_name,$contacter='')
    {
    	$where['item_id'] = $this->id;
    	$where['fee_name'] = $fee_name;
       // dd($contacter);
         if($contacter){
            $where['pay_contacter'] = $contacter;
        }
    	return ItemFee::where($where)->value('pay_money');
    }
}
